const express = require("express");

const router = express.Router();

const bannerHandler = require("../router_handler/banner");

const uuid = require("uuid");

const path = require("path");

const multer = require("multer");
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, path.join(__dirname, "../assets"));
  },
  filename: function (req, file, cb) {
    let urlArr = file.originalname.split(".");
    cb(null, file.fieldname + "_" + uuid.v4() + '.' + urlArr[urlArr.length - 1]);
  }
});

const upload = multer({ storage: storage });

router.post("/addBanner", upload.single("banner"), bannerHandler.addBanner);

router.get("/getBanner", bannerHandler.getBanner);

module.exports = router;